Skip to content

fix(mobile-gui): dispatch resize event when orientation gate is dismissed#696

Merged
takaokouji merged 4 commits into
developfrom
fix/issue-695-orientation-gate-blockly-resize
May 21, 2026
Merged

fix(mobile-gui): dispatch resize event when orientation gate is dismissed#696
takaokouji merged 4 commits into
developfrom
fix/issue-695-orientation-gate-blockly-resize

Conversation

@takaokouji
Copy link
Copy Markdown

@takaokouji takaokouji commented May 21, 2026

Summary

dismiss 直後と、MobileGui ↔ desktop GUI 切り替え直後の 2 箇所で windowresize イベントを撃ち、Blockly に toolbox / flyout の再レイアウトを促す。これによりコードタブの PaletteToggle (◀/▶) が消えていた不具合を解消する。

Fixes #695

Root Cause

Blocks コンポーネント (packages/scratch-gui/src/containers/blocks.jsx 220–232) の shouldComponentUpdate は限られた prop 変化しか拾わない。PaletteToggle は render() 内で toolbox = this.workspace.getToolbox() が真の場合のみ描画されるが、Blockly workspace が初期化される瞬間の dimension が不正だと未計測のまま固定される。

そのトリガーが 2 通り存在する:

  1. dismiss: MobileOrientationGate の overlay 配下で初期化された workspace は、overlay を消しても resize 機会が無く未計測のまま。
  2. MobileGui ↔ desktop GUI swap: ResponsiveGui が <MobileGui><GUI> を入れ替える瞬間、新しい React サブツリーが mount される。ブラウザ自体の resize イベントは swap 前に発火しているため、新しい workspace には届かない。

タブ切替で復活していたのは、Blocks.componentDidUpdateisVisible 変化で workspace.setVisible(true)vm.refreshWorkspace()window.dispatchEvent(new Event('resize')) を実行するため (blocks.jsx:268–296)。実機 portrait → landscape 回転の場合はブラウザが自動で resize を撃つため発生しなかった。

Changes Made

  • src/components/mobile-orientation-gate/mobile-orientation-gate.jsx: handleDismisswindow.dispatchEvent(new Event('resize')) を追加
  • src/lib/responsive-gui.jsx: isNarrow が変化したタイミングで useEffect から resize を撃つ (初回 mount はスキップ)
  • test/unit/components/mobile-orientation-gate.test.jsx: dismiss クリックで resize が発火することを検証する unit テスト追加
  • test/unit/lib/responsive-gui.test.jsx: 初回 mount では resize を撃たないこと、narrow / wide を切り替えると都度 resize を撃つことを検証する unit テスト追加

Test Coverage

  • mobile-orientation-gate.test.jsx: 9 件 pass (新規 1 件)
  • responsive-gui.test.jsx: 6 件 pass (新規 2 件)

Definition of Done

  • ユニットテスト pass (15/15)
  • lint pass
  • CI green
  • ブラウザ確認 (Playwright MCP / プレビュー URL):
    • PC viewport (例: 700×900 縦長) で警告が表示される
    • 「このまま使う」を押した直後、コードタブの PaletteToggle (◀/▶) が表示されている
    • その後 900×700 (横長) にリサイズしても PaletteToggle が表示されたままである
    • 700×900 ↔ 900×700 を繰り返しても PaletteToggle が消えない
    • タブ切替なしでパレット開閉が正常に動作する
    • iPhone 縦持ち viewport (390×844) でも同様に動作する

SP / iPad 影響

  • 触ったファイル: src/components/mobile-orientation-gate/ + src/lib/responsive-gui.jsx(SP / 切替判定)
  • mobile-ui ルール §2.2 の設計原則と整合: resize を撃つだけで新規 UI / フラグの追加なし
  • viewport プリセット: PC 700×900 ↔ 900×700、iPhone 縦 (390×844) で確認予定

Related Issues

Fixes #695

Surfaced by PR #693 (Issue #691) の dismiss 機能追加に伴うユーザーテストで発見。

…ssed

dismiss 時に window resize イベントを発火し、Blockly に toolbox / flyout の
再レイアウトを促す。これがないと、orientation gate に画面を覆われた状態で
Blocks コンポーネントが初期化されたままになり、PaletteToggle が描画されない
不具合が dismiss 直後に発生する (タブ切替で復活する症状の根本原因)。

実機 portrait → landscape 回転時はブラウザが自動で resize を撃つため不要だが、
dismiss は viewport が変わらないので明示的に発火する必要がある。

Fixes #695
@github-actions
Copy link
Copy Markdown

…re-measures

useIsNarrowScreen の値が変化したタイミング (= ResponsiveGui が <MobileGui> と
<GUI> を入れ替える瞬間) に、新しい React サブツリーで初期化される Blockly
workspace へ明示的な resize イベントを撃つ。これがないと、新しい workspace
が初期描画時の getBBox / getBoundingClientRect 結果のまま固まり、
PaletteToggle (◀/▶) の親要素が null 扱いになって描画されない。

ブラウザの resize イベントは swap 前に既に発火しているため、新しい
workspace には届かない。useEffect で swap 後 (commit 後) に dispatch する
ことでこの問題を回避する。

Refs #695
…n change

`this.workspace` is an instance variable, not React state, so `inject()`
in `componentDidMount` does not trigger a re-render. The first `render()`
runs with `workspace=null`, skipping PaletteToggle. Calling
`_applyPaletteVisibility` at the end of `componentDidMount` forces a
re-render after the workspace is ready, so PaletteToggle appears on
mount regardless of dismiss state or portrait/landscape cycle.

The `window.resize` workarounds in `ResponsiveGui` and
`MobileOrientationGate` are now redundant and removed.

Fixes #695
@takaokouji takaokouji merged commit 0b42d2a into develop May 21, 2026
9 checks passed
@takaokouji takaokouji deleted the fix/issue-695-orientation-gate-blockly-resize branch May 21, 2026 14:22
github-actions Bot pushed a commit that referenced this pull request May 21, 2026
…-orientation-gate-blockly-resize

fix(mobile-gui): dispatch resize event when orientation gate is dismissed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(mobile-gui): dispatch resize event when orientation gate is dismissed to restore PaletteToggle

1 participant